<?php
namespace Home\Controller;
use Home\Model\ReferModel;
use Think\Controller;

class HomeController extends Controller {

   public function __construct() {
       parent::__construct();


       //站长推荐的hot 6篇文章
       $click = M('Article')->field('art_id,art_title,art_view')->order('art_view desc')->limit(5)->select();
       foreach ($click as $key => $value) {
           $click[$key]['art_title'] =  mb_substr($value['art_title'],0,20,'utf-8') . '...';

       }

       //云标签
       $tag = M('Article')->field('art_id,art_tag')->order('pub_time desc')->limit(13)->select();

       $tags = '';
       foreach ($tag as $key => $value) {
           $tags .= $value['art_tag'].',';

       }
       $tags = trim($tags,',');
       $tags  =  array_slice(explode(',',$tags),0,13);

       $color=array("default","primary","warning","danger","info","success","default","primary","warning","danger","info","success","warning");
       $tags = array_combine($tags,$color);

       $this->assign('tags',$tags);

       //友情链接取5条
       $link = M('Link')->field('link_url,link_name')->order('link_order asc')->select();

       //友情链接的文本颜色
       $color=array("text-muted","text-primary","text-warning","text-danger","text-info",'text-success');
       //随机取出键 text-muted，text-primary
       //随机打乱 颜色 传地址引用
        shuffle($color);

       //获取导航
       $nav = M('Nav')->field('nav_word,nav_name,nav_url')->order('nav_order asc')->select();

        $map['parent_id'] = 0;
       $cat = M('Category')->where($map)->select();
        foreach ($cat as $key => $value) {
            $tree[] = D('Category')->getCatTree($value['cat_id']);
        }

       $this->assign('tree', $tree);
       $this->assign('color', $color);
       $this->assign('link', $link);
       $this->assign('click', $click);
       $this->assign('nav', $nav);

   }

    //空方法操作，屏蔽不存在的页面
    public function _empty(){
        $this->error('你访问的页面不存在！请你重新访问。');
    }


}
